from flask import Flask, views
import functools

app = Flask(__name__)

# 装饰器
def wapper(func):
    @functools.wraps(func)
    def inner(*args, **kwargs):
        return func(*args, **kwargs)
    return inner

@app.route('/index', methods=['GET', 'POST'])
@wapper
def index():
    return 'xxxx'


class IndexView(views.View):
    methods = ['GET']
    decorators = [wapper, ]

    def dispatch_request(self):
        print('index')
        return 'index'


app.add_url_rule('/index', view_func = IndexView.as_view(name='index'))

if __name__ == '__main__':
    app.run()